﻿/*
Copyright (c) 2007 Eduardo G. Pons Dias da Costa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
//*/
import com.thelab.tween.*;

/**
* Class that describes a Tweening Element. It contains all data necessary to execute an Object tweening.
* @author Eduardo Dias da Costa
* @version 0.9a
*/
class com.thelab.tween.TweenNode
{	
	/**
	* Target Object that will be tweened.
	*/
	var _target,
	/**
	* Parameter that will be passed when the Tween End callback will be invoked.
	*/
	_cbParam,	
	/**
	* Shortcut to the function data in the TweenFunction class.
	*/
	_function;
	/**
	* Array of Objects containing all property data (aka name,values,...).
	*/
	//var _property:Array;	
	var _property:Object;
	/**
	* Command String that will set all parameters of the TweenNode.
	*/
	var _command:String,	
	/**
	* Name of the choosed transition.
	*/
	_transition:String,
	/**
	* Indicates the type of tweening being made.
	*/
	_mode:String,
	/**
	* Name of the Callback Function that will be invoked after the Tween Ending.
	*/
	_callback:String;
	/**
	* TweenNode Unique Identifier.
	*/
	var _id:Number,
	/**
	* Wich Motor the Node is located.
	*/
	_motorId:Number,
	/**
	* Time First Parameter. The time that the tween will wait before starting.
	*/
	_t0:Number,
	/**
	* Time Second Parameter. The time that the tween will last;
	*/
	_tf:Number,	
	/**
	* Time Init Reference. Current getTimer() state of the execution.
	*/
	_tstart:Number,
	/**
	* Adjust Time. Holds the number of milliseconds that the tween is paused, in order to adjust the tween execution time after unpause.
	*/
	_tpause:Number,
	/**
	* The total time duration of the tween.
	*/
	_duration:Number,
	/**
	* Time to wait before other tweens that are running stop.
	*/
	_delay:Number,
	/**
	* Global Reference time for the tween. 
	*/
	_clock:Number,
	/**
	* Number of milliseconds that the tween is running.
	*/
	_elapsed:Number,
	/**
	* Number of milliseconds until the tween is discarded after finish.
	*/
	_cooldown:Number,
	/**
	* Ratio of _elapsed/_duration. Gives the percentage of execution so far.
	*/
	_ratio:Number;
	/**
	* Flag that indicates if the Tweening have to be pause.
	*/
	var _pause:Boolean;
	/**
	* Flag that indicates frame based timing.
	*/
	var _isFrame:Boolean;
	/**
	* Flag that indicates if the Tweening is synchronized with the global clock.
	*/
	var _sync:Boolean;
	/**
	* Flag that indicates if the TweenNode is initialized.
	*/
	var _hasInit:Boolean;
	/**
	* Flag that indicates if the Tween has ended and it's currentl in cooldown.
	*/
	var _hasEnded:Boolean;
	/**
	* Flag that indicates if the path tween will orient the target
	*/
	var _orient:Number;
	/**
	* Shortcut to a Math function.
	*/
	var _math:Function;
	/**
	* Shortcut to the TweenFunction solving function.
	*/
	private var _solve:Function;
	/**
	* Shortcut to the TweenFunction solving function.
	*/
	private var _wave:Function;
	/**
	* Shortcut to the TweenFunction catmull solving function;
	*/
	private var _catmull:Function;
	/**
	* Shortcut to TweenFx function;
	*/
	private var _isFx:Function;	
	/**
	* Shortcut to TweenFx function;
	*/
	private var _addFx:Function;
	/**
	* Shortcut to TweenFx function.
	*/
	private var _hex2Obj:Function;
	
	/**
	* Shortcut to the TweenFunction functions container
	*/
	private var _tweenfunc:Object;	
	
	
	
	
	/**
	* Class constructor.
	* @param	target Object that the tween will affect.
	* @param	delay Time to wait before other tweens finishes.
	* @param	id Unique identifier.
	* @param	command String containing all information of the tween.
	* @param	param Data passed to the TWeen End callback.
	*/
	function TweenNode(motor_id:Number,target,delay:Number,id:Number,command,param)
	{
		_id = id;
		_target = target;
		//if(_target["$$LitrCache"]==undefined) _target["$$LitrCache"]={_reference:0};
		_motorId = motor_id;
		_command = command;		
		_mode = "tween";
		_transition = "outcubic";
		_solve = TweenFunction.solve;
		_wave = TweenFunction.wave;
		_catmull = TweenFunction.catmull;
		_isFx = TweenFx.isFx;
		_addFx = TweenFx.addFx;
		_hex2Obj = TweenFx.hex2Obj
		_tweenfunc = TweenFunction._function;		
		_tstart = _t0 = _tf = _tpause = _duration = _clock = _elapsed =  _ratio = 0;		
		_cooldown = 1000;
		_delay = delay;					
		_callback = "";
		_orient = Number.NaN;
		_sync = _hasInit = _hasEnded = _pause = _isFrame = false;
		_cbParam = param;
		_property = parse(command);
		if(_hasEnded)
		{
			checkInit();
			updateValues(1.0);
		}
				
	}
	
	/**
	* Extract all data of the command String.
	* @param	command Command String.
	* @return Array - List of Objects that contains all Parameters relevant data.
	*/
	private function parse(command:String) : Object
	//private function parse(command:String) : Array
	{
		var obj:Object = {};
		//var obj:Array = [],		
		var com_list:Array = command.split(";"),				
		var_list:Array,		
		prop:Array,
		temp:Array,
		ch_list:Array = ["R","G","B","A"],
		pair:Array;
		var skip:Boolean;
		var hasFx:Boolean=false;
		var v:String,
		d:String,
		s:String;		
		
		var p0:Number,
		p1:Number,
		p_len:Number,
		j:Number,
		k:Number,
		id:Number,
		var_len:Number,
		com_len:Number = com_list.length;
		var color:Object,
		c1:Object,
		c2:Object;
		com_list.sort(sortVar);		
		////trace(com_list); return null;
		for(var i:Number=0;i<com_len;i++)
		{			
			var_list = com_list[i].split(":");			
			if(var_list.length==1) var_list = com_list[i].split("=");
			var_len = var_list.length;
			prop = [];
			skip = false;
			
			for(j=0;j<var_len;j++)
			{				
				
				v = removeSpace(var_list[j]);
				
				var_len = var_list.length;
				
				switch(v)
				{
					case "fr":
					{
						_isFrame = true;
					}
					case "t":
					{
						d = var_list[++j];
						pair = d.split(",");
						_t0 = (pair[1]==undefined)?0:Number(pair[0]);
						_tf = (pair[1]==undefined)?Number(pair[0]):Number(pair[1]);										
						_t0 = _t0*((_isFrame)?1:1000);
						_tf = _tf*((_isFrame)?1:1000);
						_duration = _tf;
						continue;
					}
					
					case "f":
					{
						s = removeSpace(var_list[++j]);					
						_transition = s
						continue;
					}
					
					case "c":
					{						
						_callback = removeSpace(var_list[++j]);
						continue;					
					}
					
					case "m":
					{						
						_math = Math[removeSpace(var_list[++j])];
						continue;
					}
					
					case "_scale":
					{						
						var_list = ["_xscale","_yscale",String(var_list.pop())];						
						j--;
						continue;						
					}
					case "_orient":
					{
						_orient = Number(removeSpace(String(var_list.pop())));
						continue;
					}
					case "_catmull":
					{		
												
						temp = removeSpace(String(var_list.pop())).split(",");						
						var isNum:Boolean = !isNaN(temp[0]);
						var tp:String = (isNum)?"number":"object";						
						var P:Array = [];						
						var end:Number = temp.length-((isNum)?1:0),
						step:Number = (isNum)?2:1,
						px:Number,py:Number;
						for(k=0;k<end;k+=step)
						{	
							if(isNum)
							{
								px = Number(removeChar(temp[k],"("));
								py = Number(removeChar(temp[k+1],")"));														
								P.push({_x: px,_y: py});
								continue;
							}							
							var ref = repath(temp[k]);
							//trace(ref._name);
							P.push(ref);							
						}
						_mode = "path";
						//obj.push({mode:"path",name:"_catmull",v0:0,vf:0,path:P,path_len:P.length,type:tp,duration:_duration,start:0,elapsed:0});
						obj["_catmull"] = {mode:"path",name:"_catmull",v0:0,vf:0,path:P,path_len:P.length,type:tp,orient:_orient};
						continue;
					}
					case "_color":
					{						
						pair = String(var_list.pop()).split(",");
						
						if(pair.length==1)
						{
							color = _hex2Obj(Number(removeSpace(pair[0])));
							com_list = com_list.concat(["_colorR:"+color.r,"_colorG:"+color.g,"_colorB:"+color.b]);
							//com_list.push("_colorR:"+color.r); com_list.push("_colorG:"+color.g);	com_list.push("_colorB:"+color.b);
							skip = true;
							break;
						}
						c1 = _hex2Obj(Number(removeSpace(pair[0])));
						c2 = _hex2Obj(Number(removeSpace(pair[1])));
						com_list = com_list.concat( ["_colorR:"+c1.r+","+c2.r,"_colorG:"+c1.g+","+c2.g,"_colorB:"+c1.b+","+c2.b]);
						//com_list.push("_colorR:"+c1.r+","+c2.r);	com_list.push("_colorG:"+c1.g+","+c2.g);	com_list.push("_colorB:"+c1.b+","+c2.b);
						skip = true;
						break;						
					}
					case "_gradfilter":
					case "_gradient":
					{
						s = removeSpace(String(var_list.pop()));						
						temp = s.split(",");						
						p_len = temp.length;
						_target["$$_colorList"]=[];												
						for(var  c:Number=0;c<p_len;c++)
						{
							k = Number(temp[c]);	
							_target["$$_colorList"].push(k);
							//trace("\t·"+k);
							//*/							
						}	
						//*/
						var_list.push("0,1");
						break;
						
					}
					case "_glowcolor":
					{						
						pair = String(var_list.pop()).split(",");
						if(pair.length==1)
						{
							color = _hex2Obj(Number(removeSpace(pair[0])));
							//com_list = com_list.concat(["_glowR:"+color.r,"_glowG:"+color.g,"_glowB:"+color.b]);
							com_list.push("_glowR:"+color.r);	com_list.push("_glowG:"+color.g);com_list.push("_glowB:"+color.b);
							skip = true;
							break;
						}
						c1 = _hex2Obj(Number(removeSpace(pair[0])));
						c2 = _hex2Obj(Number(removeSpace(pair[0])));
						//com_list = com_list.concat(["_glowR:"+c1.r+","+c2.r,"_glowG:"+c1.g+","+c2.g,"_glowB:"+c1.b+","+c2.b]);
						com_list.push("_glowR:"+c1.r+","+c2.r);	com_list.push("_glowG:"+c1.g+","+c2.g);	com_list.push("_glowB:"+c1.b+","+c2.b);
						skip = true;   
						break;						
					}
					
					case "_cfR0":
					case "_cfR1":
					case "_cfR2":
					case "_cfR3":
					case "_cfR4":
					case "_cfG0":
					case "_cfG1":
					case "_cfG2":
					case "_cfG3":
					case "_cfG4":
					case "_cfB0":
					case "_cfB1":
					case "_cfB2":
					case "_cfB3":
					case "_cfB4":
					case "_cfA0":
					case "_cfA1":
					case "_cfA2":
					case "_cfA3":
					case "_cfA4":
					{
						id = Number(v.charAt(4));
						v = v.slice(0,4);						
						break;
					}
					
					case "_colorfilter":
					{						
						temp = removeSpace(String(var_list.pop())).split("],[");						
						var temp_len:Number = temp.length, n1:Number,n2:Number;
						var ch:String;						
						if(temp_len==1)
						{							
							temp = s.split(",");
							temp_len = temp.length;
							for(k=0;k<temp_len;k++)
							{			
								id = k%5;
								ch = ch_list[int(k/5)];
								n1 = Number(removeChar(temp[k],(k==0)?"[":"]"));
								////trace("\t·"+"_cf"+ch+""+id+":"+n1);
								com_list.push("_cf"+ch+""+id+":"+n1);
							}
							id=undefined;
							skip = true; 
  							break;
						}
						var l0:Array, l1:Array;
						l0 = temp[0].split(",");
						l1 = temp[1].split(",");						
						temp_len = l0.length;
						for(k=0;k<temp_len;k++)
						{			
							id = k%5;
							ch = ch_list[int(k/5)];
							n1 = Number(removeChar(l0[k],(k==0)?"[":"]"));
							n2 = Number(removeChar(l1[k],(k==0)?"[":"]"));
							////trace("\t·"+"_cf"+ch+""+id+":"+n1+","+n2);
							com_list.push("_cf"+ch+""+id+":"+n1+","+n2);
						}
						id=undefined;
						skip = true;						
						break;						
					}
				}
				if(skip) break;
				if(_isFx(v))
				{					
					//trace("TweenNode> SpecialFx: "+v+""+((id==undefined)?"":id));
					_addFx(_target,v,id);
					v = "$$"+v+""+((id==undefined)?"":id);
					
				}
				
				
				k = v.lastIndexOf("$wv");
				if(k>=0)
				{	
					
					v = removeSpace(v);
					s = v.substr(0,k);
					if(_isFx(s))
					{
						//trace("TweenNode> SpecialFx: "+v+""+((id==undefined)?"":id));
						_addFx(_target,s,id);
						s = "$$"+s+""+((id==undefined)?"":id);
					
					}
					v=removeChar(v.substr(k+4,v.length-1),")");
					
					temp = v.split(",");
					com_list.pop();
					com_list = com_list.concat([s+"$off:"+temp[0],s+"$frq:"+temp[1],s+"$phs:"+temp[2],s+"$rng:"+temp[3],s+"$scl:"+temp[4]]);					
					i--;
					continue;
				}
				//*/
			
				if(j>=var_len-1) break;				
				pair = var_list[var_len-1].split(",");
				p0 = Number(removeSpace(pair[0]));
				p1 = Number(removeSpace(pair[1]));
				p_len = pair.length;
				
				//obj.push({mode:"tween",name:v,v0:((p_len==1)?undefined:p0),vf:((p_len==1)?p0:p1),_duration:_duration,_start:0,elapsed:0});
				
				obj[v] = {mode:"tween",name:v,v0:((p_len==1)?undefined:p0),vf:((p_len==1)?p0:p1),_duration:_duration,_start:0,elapsed:0};
			}
			
			com_len = com_list.length;
			
		}
		
		if(_duration<=0)
		{
			//trace("TweenNode> No time passed. Initialization only!");			
			_hasEnded = true;
		}
		return obj;
	}
	
	/**
	* When the tween starts it check the synchronization with the main clock.
	*/
	private function checkSync()
	{
		
		if(!_sync)
		{
			//trace("Litr> Init Prop: "+_target);
			_tstart = _clock;			
			_sync = true;			
			_target["$$isTweening"] = true;
			if(_target["$$tweenNum"]==undefined)_target["$$tweenNum"]=0
			if((_target["$$tweenNum"]++)==0)
			{
				_target["$$cache"] = {};				
			}			
			Litr.callEvent("start",this);
		}		
	}
	private function checkOverwrite(prop:String)
	{
		
		if((_target["$$cache"])[prop]==undefined)
		{
			//trace("TweenNode> Property is not being tweened!");
			(_target["$$cache"])[prop] = _id;
		}
		else
		{
			//trace("TweenNode> Property is tweening! "+prop+" "+_motorId+" "+_id);
			Litr.killProperty(prop,(_target["$$cache"])[prop]);
			(_target["$$cache"])[prop] = _id;
		}
		
	}
	/**
	* When the tween starts it initialize (if necessary) the Target Objects tweened parameters.
	*/
	private function checkInit()
	{
		if(_hasInit)return;
		
		var p:Object;
		var pn:String;
		var i:String;
		var v0:Number;
		var len:Number = _property.length;
		//for(var i:Number=0;i<len;i++)
		for(i in _property)
		{
			p = _property[i];
			pn = p.name;
			v0 = p.v0;
				if(v0 != undefined) 
					_target[pn] = v0;
				else
				{
					_target[pn] = (_target[pn]==undefined)?p.vf:_target[pn];
					p.v0 = _target[pn];
				}				
			checkOverwrite(i);
			
			//trace("\t· "+p.name+" = "+"["+p.v0+","+p.vf+"] "+v0);
				
			
		}		
		//trace("TweenNode> References now "+_target["$$LitrCache"]._reference);
		_function = _tweenfunc[_transition];
		_hasInit=true;
	}
	
	/**
	* Checks the flag of Pause, and if necessary pauses the tween execution.
	* @return Boolean - Flag indicating if the tween was unpaused.
	*/
	private function checkPause():Boolean
	{
		if(_pause)
		{
			_tpause = (_clock -  _elapsed) - _t0;
			////trace("paused: "+_tpause);			
			return true;
		}
		return false;
	}
	
	/**
	* Checks if the initial delay time has ended.
	* @return Flag - Indicating if the tween should start.
	*/
	private function checkWait() : Boolean
	{
		
		if(_elapsed<0)
		{			
			////trace("\t waiting: "+_elapsed+" r: "+_ratio);
			return true;
		}
		checkInit();
		return false;
	}
	
	/**
	* Check if the tween reached it's end.
	*/
	private function checkEnd()
	{
		if((_elapsed>=_duration)&&(!_hasEnded))
		{
			////trace(_ratio);
			updateValues(1.0);			
			_elapsed = _duration;			
			_target[_callback](this,_cbParam);
			Litr.callEvent("stop",this);
			_hasEnded = true;
			_tstart = _clock;
		}		
		
	}
	/**
	* Checks if the tween has cooled down and can be deleted.
	* @return
	*/
	private function checkCooldown() : Boolean
	{
		
		if(_hasEnded)
		{
			_elapsed = (_clock -  _tstart);			
			
			if(_elapsed>_cooldown)
			{	
				_target["$$isTweening"] = false;
				--_target["$$tweenNum"];
				//if((--_target["$$tweenNum"])<=0) delete _target["$$cache"];
				return true;
			}
		}
		
		return false;
	}
	
	/**
	* Updates the values according to the time of execution and transition function choosed.
	* @param	ratio - Percent of execution so far.
	*/
	private function updateValues(ratio:Number)
	{
		
		_ratio = ((_ratio = (ratio==undefined)?(((_elapsed<_duration)?_elapsed:_duration)/_duration):ratio)>1.0)?1.0:_ratio;
		
		
		
		var p:Object,
		pos:Object;
		var n:String, tp:String//;
		,i:String;
		var v0:Number,
		//i:Number,
		vf:Number,
		r:Number,	
		len:Number = _property.length,
		p0:Number,p1:Number,p2:Number,p3:Number,p_len:Number,r_len:Number,
		freq:Number,amp:Number,off:Number,phs:Number,scl:Number,d:Number = _duration*0.0062831853071796;
		var isWave:Boolean;
		
		var path:Array;
		//for(i=0;i<len;i++)
		for(i in _property)
		{
			p  = _property[i];
			n  = p.name;
			//n  = i;
			v0 = p.v0;
			vf = p.vf;		
			tp = typeof(_function);
			
			switch(_mode)
			{	
				case "tween":
				{
					
					switch(tp)
					{
						case "object":
						{						
							r  = _solve(_function,_ratio);
							_target[n] = v0 + ((vf-v0)*r);							
							//trace(n+" "+_target[n]+" "+v0+" "+vf);
							break;
						}
						case "function":
						{
							isWave = ((_transition.charAt(0)=="w") && (_transition.charAt(1)=="v"));
							if(isWave)
							{
								
								freq = ((freq =(_target[n+"$frq"]))==undefined)?0:freq;
								amp = ((amp =  (_target[n+"$rng"]))==undefined)?0:amp;
								off = ((off =  (_target[n+"$off"]))==undefined)?0:off;								
								phs = ((phs =  (_target[n+"$phs"]))==undefined)?0:phs;
								scl = ((scl =  (_target[n+"$scl"]))==undefined)?1:scl;
								_target[n] = vf + _wave(freq*d*_ratio,amp,off,phs*0.0174532925199433,scl,_function);	
								
								//trace(n+" "+off+" "+freq+" "+amp+" "+scl+" "+_wave(freq*d*_ratio,amp,off,phs,scl,_function)+" "+_target[n]);
								//trace(n+" "+_wave(freq*d*_ratio,amp,off,phs,scl,_function));
								
							}
							break;
						}
					}
					if(_math!= undefined) _target[n] = _math(_target[n]);
					if(n=="_alpha") _target._visible = (!(_target._alpha<0));
					break;
				}
				case "path":
				{					
					switch(tp)
					{
						case "object":
						{						
							r  = _solve(_function,_ratio);							
							break;
						}
						case "function":
						{
							isWave = ((_transition.charAt(0)=="w") && (_transition.charAt(1)=="v"));
							if(isWave)
							{
								freq = ((freq = (_target[n+"$frq"]))==undefined)?0:freq;
								amp = ((amp = (_target[n+"$rng"]))==undefined)?1:amp;
								off = ((off = (_target[n+"$off"]))==undefined)?0:off;								
								phs = ((phs = (_target[n+"$phs"]))==undefined)?0:phs;
								scl = ((scl = (_target[n+"$scl"]))==undefined)?1:scl;
								r = _wave(freq*d*_ratio,amp,off,phs*0.0174532925199433,scl,_function);
								//trace(n+" "+freq+" "+amp+" "+off+" "+(freq*_duration*360*_ratio/1000)+" "+_wave(freq*d*_ratio,amp,off,phs,_function)+" "+_target[n]);
							}
							break;
						}
					}
					p_len = p.path_len-1;
					path = p.path;
					r = (r<0)?0:((r>1)?1:r);					
					r_len = ((p_len)*r);	
					p1 = int(r_len);
					p2 = p1+1;					
					p0 = ((p0 = p1-1)>0) ? p0 : 0;						
					p3 =((p3 = p1+2)<(p_len))?p3:(p_len);
					pos = _catmull(r_len-p1,path[p0],path[p1],path[p2],path[p3],!isNaN(_orient));
					if(!isNaN(_orient))
					{
						_target._rotation = pos.a + _orient;						
					}
					//trace(r+" "+p0+" "+p1+" "+p2+" "+p3+" "+(p_len));									
					_target._x = pos.x;
					_target._y = pos.y;
					break;
				}				
			}
			
			////trace("r: "+_ratio+" t: "+_transition+" prop: "+n+" v: "+_target[n]+"["+v0+","+vf+"] f: "+_function+" res: "+r);
		}		
		
	}
	/**
	* Updates the elapsed time information.
	*/
	private function updateTime()
	{
		_elapsed = ((_clock -  _tstart) - _t0 - _delay) - _tpause;			
	}
	
	/**
	* Main execution point of the tween. IT calls all relevant functions in order to update all internal structure and the Target Parameters.
	* @param	tick - Global time information.
	* @return Boolean - Flag that indicates if the tween is finished.
	*/
	function run(tick:Number) : Boolean
	{				
		if(!_isFrame) _clock = tick; else _clock++;
		
		if(checkCooldown())
		{			
			return false;
		} else if(_hasEnded)
		{
			return true;
		}
		
		
		checkSync();
		
		if(checkPause()) return true;
		
		updateTime();
		
		if(checkWait())return true;
			
		////trace("\t id: "+_id+" r: "+_ratio+" e: "+_elapsed+" d: "+_duration);
		
		updateValues();
		
		Litr.callEvent("update",this);
		
		checkEnd();
		
		return true;
	}
	/**
	* Auxiliary function. Removes all white spaces from a string.
	* @param	str
	* @return
	*/
	private function removeSpace(str:String) : String
	{
		var len:Number = str.length;
		var s:String = "";
		var c:String;
		for(var i:Number=0;i<len;i++)
		{
			c = str.charAt(i);			
			if(c==" ") continue;
			s += c;
		}
		return s;
	}
	/**
	* Auxiliary function. Removes all white spaces from a string.
	* @param	str
	* @return
	*/
	private function removeChar(str:String,ch:String) : String
	{
		if(ch=="") return str;
		var len:Number = str.length;
		var s:String = "";
		var c:String;
		
		for(var i:Number=0;i<len;i++)
		{
			c = str.charAt(i);			
			if(c==ch) continue;
			s += c;
		}
		return s;
	}
	/**
	* Returns the reference using the Path represented as a String in dot notation.
	* @param	path_str
	*/
	private function repath(path_str:String)
	{
		var list:Array = path_str.split(".");
		var len:Number = list.length;
		var ref = _root[list[1]];		
		for(var i:Number=2;i<len;i++)
		{
			ref = ref[list[i]];
		}
		return ref;		
	}
	
	private function sortVar(a:Object,b:Object):Number
	{
		var s1:String = String(a);
		var s2:String = String(b);
		var i1:Number = s1.indexOf("=",0);
		var i2:Number = s2.indexOf("=",0);
		if(i1!=-1) return -1;
		if(i2!=-1) return  1;		
		return 0;
	}
	
	/**
	* Converts the TweenNode into a String.
	* @return String - TweenNode information.
	*/
	function toString():String { return _target._name; }
}
